<?php
class kst_dt_receive_toko_model extends MY_Model {
	var $model = 'kst_dt_receive_toko_model';

	function GetJSON($as_pk_master)
	{
		$ls_sql	= "	SELECT	a.receive_toko_dt_id,
					a.receive_toko_id,
					a.receive_toko_dt_barang,
					a.receive_toko_dt_barcode,
					a.receive_toko_dt_kemasan,
					a.receive_toko_dt_ckemasan,
					a.receive_toko_dt_cckemasan,
					a.receive_toko_dt_pesan,
					a.receive_toko_dt_kirim,
					a.receive_toko_dt_terima,
					a.receive_toko_dt_hpokok,
					a.receive_toko_dt_hjual,
					a.receive_toko_dt_diskon,
					a.receive_toko_dt_ppn,
					a.receive_toko_dt_terima2,
					a.receive_toko_dt_catatan
					FROM	kst_order_receive_toko_dt2 a
					WHERE	a.receive_toko_id = '".$as_pk_master."' 
					ORDER BY ".(post('sort')=='' ? 'a.receive_toko_dt_id' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order')); // ".$as_pk_master."

		return json_encode( $this->paging($ls_sql) );
	}
	
	function GetDetailByID($as_pk_master)
	{
		$ls_sql	= "	SELECT	a.receive_toko_dt_id,
					a.receive_toko_id,
					a.receive_toko_dt_barang,
					a.receive_toko_dt_barcode,
					a.receive_toko_dt_kemasan,
					a.receive_toko_dt_ckemasan,
					a.receive_toko_dt_cckemasan,
					a.receive_toko_dt_pesan,
					a.receive_toko_dt_kirim,
					a.receive_toko_dt_terima,
					a.receive_toko_dt_hpokok,
					a.receive_toko_dt_hjual,
					a.receive_toko_dt_diskon,
					a.receive_toko_dt_ppn,
					a.receive_toko_dt_terima2,
					a.receive_toko_dt_catatan
					FROM	kst_order_receive_toko_dt2 a
					WHERE	a.receive_toko_id = '".$as_pk_master."' 
					ORDER BY ".(post('sort')=='' ? 'a.receive_toko_dt_id' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order')); // ".$as_pk_master."
		
		$result	= $this->db->query($ls_sql);

		if($result->num_rows() > 0){
			return $result->result_array();
		}else{
			return NULL;
		}
	}
	
	
	function Add($arr_data){
		$this->db->insert('kst_order_receive_toko_dt2', $arr_data);	
	}
	
	function Update($arr_data, $arr_rule){
		$this->db->update('kst_order_receive_toko_dt2', $arr_data, $arr_rule);
	}
	
	function GetSingle($as_roleid){
		$result = $this->db->get_where('kst_order_receive_toko_dt2', array('receive_toko_dt_id' => $as_roleid));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}
	
	function GetSingleView($as_roleid)
	{
		$result = $this->db->get_where('kst_order_receive_toko_dt2', array('receive_toko_dt_id' => $as_roleid));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}

	function DeleteSingle($arr_rule)
	{
		try {
			$this->db->delete('kst_order_receive_toko_dt2', $arr_rule);
			return '';
		} catch(Exception $e) {
			return $e->getMessage();
		}
	}
}
?>